package com.cn.zpark;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: RequestDemo04
 * @Description:
 * @author: RZS
 * @date: 2022/4/11  15:28
 */
@WebServlet("/rd4.do")
public class RequestDemo04 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 响应内容
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.println("<h1>转达之前的请求servletDemo04</h1>");

        // 请求域绑定数据
        request.setAttribute("name", "中关村软件园");
        request.setAttribute("desc", "中关村软件园号称中国硅谷");

        // 转发给Demo05进行处理
        // 获取转发器
        RequestDispatcher dispatcher = request.getRequestDispatcher("rd5.do");
        // 执行转发
        dispatcher.forward(request, response);

        writer.close();
    }
}
